package com.goldenKey.admin.controller;

import com.goldenKey.common.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.goldenKey.common.pojo.po.Category;
import com.goldenKey.admin.service.ICategoryService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/02/02
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private ICategoryService categoryService;

	/**
	 * 新增数据
	 * @param category
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Category category) {
		categoryService.save(category);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param categoryId
	 * @return
	 */
	@DeleteMapping("/deleteById/{categoryId}")
	public R<Void> deleteById(@PathVariable("categoryId") Integer categoryId) {
		categoryService.removeById(categoryId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param category
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Category category) {
		categoryService.updateById(category);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param categoryId
	 * @return
	 */
	@GetMapping("/getById/{categoryId}")
	public R<Category> getById(@PathVariable("categoryId") Integer categoryId) {
		Category category = categoryService.getById(categoryId);
		return R.ok(category);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Category>> list() {
		List<Category> categoryList = categoryService.list();
		return R.ok(categoryList);
	}

}